/*
 *
 *方法的整理与重构
 *
 *
 */

//定义app参数名称，并加载其它模块
var authApp=angular.module('authapp', ["ngCookies",'ngFileUpload','ui.bootstrap']);

//此为定位页面所用
authApp.value('page','schoolAlongWith');

/*controller部分*/

//主要操作controller
authApp.controller("opinionEditController",function($scope,$http,$getQueryString,$timeout,$sce){
     $scope.cc = location.search.substr(1).split("+")[2]
     $scope.pid = location.search.substr(1).split("+")[3]
	 var sign=decodeURIComponent(location.search.substr(1).split("+")[0]);
     var schoolId=decodeURIComponent(location.search.substr(1).split("+")[1]);
     var pid = null
     //var f = $getQueryString("f");

	   $http({
        method:'post',
        url:apis.queryOneCR,
        data:{'schoolId':schoolId,'sign':sign},
    }).success(function(response){
        if(response.code=="000000"){
        	console.log(response)
            var arr = response.data;
            $scope.schoolId = arr.schoolName;
            $scope.kind = arr.kind;
            $scope.reportingTime = arr.reportingTime;
            $scope.teacher = arr.teacher;
            $scope.subject = arr.subject;
            $scope.classs = arr.classs;
            $scope.teachingTime = arr.teachingTime;
            $scope.weekClassHours = arr.weekClassHours;
            $scope.technicalTitle = arr.technicalTitle;
            $scope.teachContent = arr.teachContent;
            $scope.level = arr.level;
            $scope.generalComment = arr.generalComment;
            pid = arr.pid
        }else{
            alert(response.errorMsg);
        }
    }).error(function(){
        alert("服务器打瞌睡了，请稍等！");
        $scope.isAddPwd=true;
    })
    $scope.skip = function(){
    	
    	location.href = paths.path.schoolAlongWith;
    }

    $scope.down=function() {
        return window.open('/views/investiga/table12.html?'+sign+'+'+schoolId)
    }

    $scope.save_a = function(){
        var obj = {
            'schoolId':location.search.substr(1).split("+")[1],
            'kind':$scope.kind,
            'reportingTime':$scope.reportingTime,
            'teacher':$scope.teacher,
            'subject':$scope.subject,
            'classs':$scope.classs,
            'teachingTime':$scope.teachingTime,
            'weekClassHours':$scope.weekClassHours,
            'technicalTitle':$scope.technicalTitle,
            'teachContent':$scope.teachContent,
            'level':$scope.level,
            'generalComment': $scope.generalComment
        }
        if ($scope.pid) {
            console.log($scope.pid)
            obj.pId = pid
        }
          $http({
            method:'post',
            url:apis.updateCourseRecord,
            data:obj,
        }).success(function(response){
            if(response.code=="000000"){
                location.href = paths.path.seeInformation+"?"+sign+"+"+schoolId;
            }else{
                alert(response.errorMsg);
            }
        }).error(function(){
            alert("服务器打瞌睡了，请稍等！");
        })
    }
})

